package com.itluma.isWOak.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itluma.isWOak.mapper.CostMapper;
import com.itluma.isWOak.pojo.Cost;
import com.itluma.isWOak.service.CostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CostServiceImpl implements CostService {
    @Autowired
    private CostMapper costMapper;
    @Override
    public Cost add(Cost cost) {
        if(costMapper.insert(cost) > 0){
            return cost;
        }
        return null;
    }

    @Override
    public Cost checkName(String name) {
        return costMapper.findByName(name);
    }


    @Override
    public PageInfo<Cost> page(Integer pageNum, Integer pageSize, String orderBy) {
        PageHelper.startPage(pageNum, pageSize, orderBy);
        List<Cost> list = costMapper.list();
        PageInfo<Cost> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public Cost showDetail(Integer costId) {
        return costMapper.findById(costId);
    }

    @Override
    public Boolean delete(Integer costId) {
        return costMapper.delete(costId) > 0;
    }

    @Override
    public Boolean enable(Integer costId) {
        return costMapper.enable(costId) > 0;
    }

    @Override
    public Boolean modify(Cost cost) {
        return costMapper.modify(cost) > 0;
    }


}
